@@ -10,6 +10,7 @@ class Agent < ActiveRecord::Base |
||
| 10 | 10 |
include AssignableTypes |
| 11 | 11 |
include MarkdownClassAttributes |
| 12 | 12 |
include JSONSerializedField |
| 13 |
+ include RDBMSFunctions |
|
| 13 | 14 |
|
| 14 | 15 |
markdown_class_attributes :description, :event_description |
| 15 | 16 |
|
@@ -127,7 +128,8 @@ class Agent < ActiveRecord::Base |
||
| 127 | 128 |
if keep_events_for == 0 |
| 128 | 129 |
events.update_all :expires_at => nil |
| 129 | 130 |
else |
| 130 |
- events.update_all "expires_at = DATE_ADD(`created_at`, INTERVAL #{keep_events_for.to_i} DAY)"
|
|
| 131 |
+ #events.update_all "expires_at = DATE_ADD(`created_at`, INTERVAL #{keep_events_for.to_i} DAY)"
|
|
| 132 |
+ events.update_all "expires_at = " + rdbms_date_add("created_at","DAY",keep_events_for.to_i)
|
|
| 131 | 133 |
end |
| 132 | 134 |
end |
| 133 | 135 |
|
@@ -0,0 +1,13 @@ |
||
| 1 |
+module RDBMSFunctions |
|
| 2 |
+ def rdbms_date_add(source, unit, amount) |
|
| 3 |
+ adapter_type = connection.adapter_name.downcase.to_sym |
|
| 4 |
+ case adapter_type |
|
| 5 |
+ when :mysql |
|
| 6 |
+ "DATE_ADD(`#{source}`, INTERVAL #{unit} #{AMOUNT})"
|
|
| 7 |
+ when :postgresql |
|
| 8 |
+ "(#{source} + INTERVAL '#{amount} #{unit}')"
|
|
| 9 |
+ else |
|
| 10 |
+ raise NotImplementedError, "Unknown adapter type '#{adapter_type}'"
|
|
| 11 |
+ end |
|
| 12 |
+ end |
|
| 13 |
+end |